package www.wxwnb.clerk.adapter;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import java.util.ArrayList;
import java.util.List;

import www.wxwnb.clerk.R;
import www.wxwnb.clerk.http.entity.ResultQueryBean;
import www.wxwnb.clerk.utils.TimeUtil;

/**
 * Created by dingguanxu on 2017/9/11.
 */

public class ResultQueryAdapter extends RecyclerView.Adapter<ResultQueryAdapter.ResultQueryViewHolder> {

    private LayoutInflater mLayoutInflater;
    private List<ResultQueryBean.DataBean.PageRecordsBean> mDataList = new ArrayList();

    public ResultQueryAdapter(Context context, List<ResultQueryBean.DataBean.PageRecordsBean> list) {
        super();
        mLayoutInflater = LayoutInflater.from(context);
        mDataList = list;
    }

    public void setData(List<ResultQueryBean.DataBean.PageRecordsBean> list) {
        mDataList = list;
        notifyDataSetChanged();
    }

    @Override
    public ResultQueryViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        return new ResultQueryViewHolder(mLayoutInflater.inflate(R.layout.adapter_result_query, parent, false));
    }

    @Override
    public void onBindViewHolder(ResultQueryViewHolder holder, int position) {
        ResultQueryBean.DataBean.PageRecordsBean b = mDataList.get(position);
        holder.one.setText(b.getUserName());
        holder.two.setText(b.getPhone());
        holder.three.setText("开户金额：¥" + String.valueOf(b.getMonery()));
        holder.bottomOne.setText("开户时间：" + TimeUtil.timestamp2DateOrString(b.getCreateTime()));
    }

    @Override
    public int getItemCount() {
        return mDataList == null ? 0 : mDataList.size();
    }

    class ResultQueryViewHolder extends RecyclerView.ViewHolder {

        TextView one, two, three, bottomOne;

        public ResultQueryViewHolder(View itemView) {
            super(itemView);
            one = (TextView) itemView.findViewById(R.id.tv_1);
            two = (TextView) itemView.findViewById(R.id.tv_2);
            three = (TextView) itemView.findViewById(R.id.tv_3);
            bottomOne = (TextView) itemView.findViewById(R.id.tv_bottom_1);
        }
    }

}
